package com.example.lizhixin.object_three_team;

import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.example.lizhixin.object_three_team.Base.BaseActivity;

public class NavigationActivity extends BaseActivity {

    private TextView time;
    private int i = 4;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            time.setText("跳过：" + msg.arg1);
            if (msg.arg1 == 0) {
                startActivity(MainActivity.class, true);
            }
        }
    };

    @Override
    protected int setLayoutId() {
        return R.layout.activity_navigation;
    }

    @Override
    protected void initView() {
        time = (TextView) findViewById(R.id.time);
        new MyThread().start();
    }

    class MyThread extends Thread {
        @Override
        public void run() {
            super.run();
            while (i > 0) {

                try {
                    Thread.sleep(1000);
                    Message message = handler.obtainMessage();
                    i--;
                    message.arg1 = i;
                    handler.sendMessage(message);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

